package com.shrct.businessprocess.project;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.project.RCEarlyBuildInfo;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectCreditStat;
import com.shrct.businessprocess.project.events.RCProjectEventsListener;
import com.shrct.businessprocess.project.impl.RCProjectCreditStatImpl;
import edu.fudan.mylang.pf.IGenericQuery;
import edu.fudan.mylang.pf.event.BaseEntityEventsListener;
import edu.fudan.mylang.utils.DateUtil;
import java.util.Date;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.project.RCProjectCreditStatCreator")
public class RCProjectCreditStatCreator extends BaseEntityEventsListener<RCProject> implements RCProjectEventsListener {
  public void ProjectAuditPassed(final RCProject entity) {RCProjectCreditStat rCProjectCreditStat=RCProjectCreditStatImpl.create(getObjectFactory());
    final Procedure1<RCProjectCreditStat> _function = new Procedure1<RCProjectCreditStat>() {
        public void apply(final RCProjectCreditStat it) {
          it.setProject(entity);
          RCEarlyBuildInfo _earlyBuildInfo = entity.getEarlyBuildInfo();
          Boolean _isEarlyBuild = _earlyBuildInfo.getIsEarlyBuild();
          it.setIsInitializedAsEB(_isEarlyBuild);
          Boolean _isInitializedAsEB = it.getIsInitializedAsEB();
          it.setIsCurrentEB(_isInitializedAsEB);
          Integer _year = entity.getYear();
          it.setYear(_year);
          RCEmployee _majorSales = entity.getMajorSales();
          it.setMajorSaler(_majorSales);
          Date _day = DateUtil.today();
          it.setStartDate(_day);
        }
      };
    ObjectExtensions.<RCProjectCreditStat>operator_doubleArrow(rCProjectCreditStat, _function);
  }
  
  public void ContractSigned(final RCProject entity, final Date date) {
    IGenericQuery<RCProjectCreditStat> query=getObjectFactory().createGenericQuery(RCProjectCreditStat.class,"select e from com.shrct.businessprocess.project.impl.RCProjectCreditStatImpl as e   where ((e.project) = (:entity)) and  e.active = 1      ").setParameter("entity",entity);
    RCProjectCreditStat _uniqueResult = query.uniqueResult();
    final Procedure1<RCProjectCreditStat> _function = new Procedure1<RCProjectCreditStat>() {
        public void apply(final RCProjectCreditStat it) {
          it.setIsCurrentEB(Boolean.valueOf(false));
          it.setEbCancelDate(date);
        }
      };
    ObjectExtensions.<RCProjectCreditStat>operator_doubleArrow(_uniqueResult, _function);
  }
  
  public void NotifyAllContractCollected(final RCProject entity) {
  }
  
  public void actUpdateTimer(final RCProject entity) {
  }
  
  public void actFixTimer(final RCProject entity) {
  }
}
